
// HCS08 erasing + unsecuring command file:
// These commands mass erase the chip then program the security byte to 0xFE (unsecured state + backdoor key mechanism enabled).

wb 0x1825 0x30 // clear FPVIOL and FACCERR in FSTAT register
wb 0x1820 49   // set clock divider for 10 MHz bus speed with FECDIV register
               // Please see below to find how to evaluate this constant value.

wb 0x1824 0xFF // remove all flash protections clearing FPROT register
                      
//mass erase flash
wb 0x1825 0x30 // clear FPVIOL and FACCERR in FSTAT register
wb 0xf000 0    // (dummy) write to flash array to buffer address and data
wb 0x1826 0x41 // write MASS ERASE command in FCMD register
wb 0x1825 0x80 // set FCBEF in FSTAT register to execute the command 
wait 10

//blankcheck flash
wb 0x1825 0x30 // clear FPVIOL and FACCERR in FSTAT register
wb 0xf000 0    // (dummy) write to flash array to buffer address and data  
wb 0x1826 0x5  // write BLANK CHECK command in FCMD register 
wb 0x1825 0x80 // set FCBEF in FSTAT register to execute the command 
wait 10

//reprogram Security byte to Unsecure state
wb 0x1825 0x30 // clear FPVIOL and FACCERR in FSTAT register
wb 0xffbf 0xfe // write NVFEOPT register in flash array to UNSECURED state with Backdoor Key Mechanism enabled
wb 0x1826 0x20 // write BYTE PROGRAM command in FCMD register  
wb 0x1825 0x80 // set FCBEF in FSTAT register to execute the command 
wait 10

reset

